/*
 * MY.example (my.example.js)
 * Convention >> http://javascript.crockford.com/code.html
 */

var MY = {};
MY.example = {
    x: function () {
        var titlePrefix = document.title;
        var rewriter = new EK.Rewriter();
        var dispatcher = new EK.Dispatcher();
        
        rewriter.rules.custom1 = {}; // add custom rewrite rules
        
        dispatcher.routes.app = { // add custom dispatch routes
            pattern: /#/,
            controller: "MY.example.AppPanelView",
            action: "x"
        };
        dispatcher.routes.dolphin = {
            pattern: /#.*\/dolphin(?:\/.*)?$/,
            controller: "MY.example.DolphinPanelPresenter",
            action: "x"
        };
        dispatcher.routes.taligent = {
            pattern: /#.*\/taligent(?:\/.*)?$/,
            controller: "MY.example.TaligentPanelPresenter",
            action: "x"
        };
        
        EK.location.debugMode = true;
        EK.location.change(function (url) {
            var rwUrl = rewriter.x(url);
            document.title = titlePrefix + " - " + rwUrl.replace(/[^#]*#?/, "");
            if (rwUrl != url) { EK.location.replace(rwUrl);	}
            dispatcher.x(rwUrl); // start dispatchin'
        });
    }
};

jQuery(function ($) {
    MY.example.x(); // x (execute) app when DOM is ready
});